﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Xml;
using System.Collections.Generic;

namespace TuyenDungViecLam.VN
{
    public partial class Huong_Nghiep : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string rssURL = "http://www.timviecnhanh.com/rss/vieclam";
                rptin1.DataSource = DocRSS(rssURL);
                rptin1.DataBind();
                //rssURL = "http://www.toquoc.gov.vn/RssPlus/Giao-Duc.rss";
                //rptin2.DataSource = DocRSS(rssURL);
                //rptin2.DataBind();
            }
        }

        public struct RSS
        {
            string _ten;

            public string Ten
            {
                get { return _ten; }
                set { _ten = value; }
            }
            string _link;

            public string Link
            {
                get { return _link; }
                set { _link = value; }
            }
        }
        public List<RSS> DocRSS(string rssURL)
        {
            // This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com
            List<RSS> listItemRss = new List<RSS>();
            // Visit http://www.AspNetTutorials.com for more ASP.NET Tutorials
            //string rssURL = "http://www.codeguru.com/icom_includes/feeds/codeguru/rss-all.xml";         
            //Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");
            listItemRss = ProcessRSSItem(rssURL);
            //Response.Write("<hr />");
            
            //Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");

            //listItemRss = ProcessRSSItem(rssURL);
            return listItemRss;

        }

        public List<RSS> ProcessRSSItem(string rssURL)
        {
            List<RSS> listRss = new List<RSS>();
            WebRequest myRequest = WebRequest.Create(rssURL);
            WebResponse myResponse = myRequest.GetResponse();

            Stream rssStream = myResponse.GetResponseStream();
            XmlDocument rssDoc = new XmlDocument();
            rssDoc.Load(rssStream);

            XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");

            string title = "";
            string link = "";
            string description = "";

            for (int i = 0; i < rssItems.Count; i++)
            {
                XmlNode rssDetail;

                RSS Rssitem = new RSS();
                rssDetail = rssItems.Item(i).SelectSingleNode("title");
                if (rssDetail != null)
                {
                    Rssitem.Ten = rssDetail.InnerText;
                }
                else
                {
                    title = "";
                }

                rssDetail = rssItems.Item(i).SelectSingleNode("link");
                if (rssDetail != null)
                {
                    Rssitem.Link = rssDetail.InnerText;
                }
                else
                {
                    link = "";
                }

                rssDetail = rssItems.Item(i).SelectSingleNode("description");
                if (rssDetail != null)
                {
                    description = rssDetail.InnerText;
                }
                else
                {
                    description = "";
                }

                listRss.Add(Rssitem);
                //Response.Write("<p><b><a href='" + link + "' target='new'>" + title + "</a></b><br/>"); 
                //Response.Write(description + "</p>"); 
            }
            return listRss;
        }
    }
}
